//
//  DataUtils.m
//  CostaCruise
//
//  Created by ChuongTran on 5/31/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "DataUtils.h"


static DataUtils *instance;

@implementation DataUtils



+(DataUtils *)shareInstanse {
	if (!instance) {
		instance = [[DataUtils alloc] init];
	}
	return instance;
}


-(void)setup {
	dataDictionary = [[self getDataDictionarySaved] retain];
}

-(void)setObject:(id)value forKey:(NSString *)key {
	if (!dataDictionary) {
		[self setup];
	}
	if (!value) {
		[dataDictionary removeObjectForKey:key];
		return;
	}
	[dataDictionary setObject:value forKey:key];
}

-(id)objectForKey:(NSString *)key{
	if (!dataDictionary) {
		[self setup];
	}
	return [dataDictionary objectForKey:key];
}

-(void)removeObjectForKey:(NSString *)key{
	if (!dataDictionary) {
		[self setup];
	}
	[dataDictionary removeObjectForKey:key];
}

-(void)save{
	if (dataDictionary) {
		[dataDictionary writeToFile:[self getDataPath] atomically:YES];
	}
}

-(NSMutableDictionary *)getDataDictionarySaved {
	NSMutableDictionary *dataSavedDictionary;
	dataSavedDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:[self getDataPath]];
	/*
	if ([[NSFileManager defaultManager] fileExistsAtPath:[self getDataPath]]) {
		dataSavedDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:[self getDataPath]];
	}else {
		dataSavedDictionary = [[NSMutableDictionary alloc] init];
	}
	 */
	return [dataSavedDictionary autorelease];
}

-(NSString *)getDataPath{
	//NSString *path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/HoleData.plist"];
	//NSString *path = @"HoleData.plist";
	NSString *path = [[NSBundle mainBundle] pathForResource:
					  @"dataBridge" ofType:@"plist"];
	return path;
}

@end
